package com.cqut.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.cqut.model.ScoreDetails;
import com.cqut.dao.ScoreDetailsMapper;
import com.cqut.service.IScoreDetailsService;
import com.cqut.util.SqlUtil;

@Service
public class ScoreDetailsService implements IScoreDetailsService {
    @Resource(name="scoreDetailsMapper")
    private ScoreDetailsMapper scoreDetailsMapper;

    @Override
    public boolean save(ScoreDetails scoreDetails) {
        return scoreDetailsMapper.insert(scoreDetails) > 0;
    }

    @Override
    public boolean update(ScoreDetails scoreDetails) {
        return scoreDetailsMapper.updateByPrimaryKeySelective(scoreDetails) >= 0;
    }

    @Override
    public boolean delete(String judgeScoreDetails) {
        return scoreDetailsMapper.deleteByPrimaryKey(judgeScoreDetails) > 0;
    }

    @Override
    public boolean batchDelete(String[] primaryKeys) {
        return scoreDetailsMapper.deleteByPrimaryKeys(primaryKeys) > 0;
    }

    @Override
    public ScoreDetails findModel(String judgeScoreDetails) {
        return scoreDetailsMapper.selectByPrimaryKey(judgeScoreDetails);
    }

    @Override
    public ScoreDetails findModel(String judgeScoreDetails, String[] parameters) {
        return scoreDetailsMapper.findModel(judgeScoreDetails, SqlUtil.formatParameters(parameters));
    }

    public Map<String, Object> findMap(String judgeScoreDetails) {
        String[][] parameters = {{"judge_score_details", "judgeScoreDetails"}, {"target_id", "targetId"}, {"score", "score"}, {"socre_suggestion", "socreSuggestion"}};
        return this.findMap(judgeScoreDetails, parameters);
    }

    public Map<String, Object> findMap(String judgeScoreDetails, String[][] parameters) {
        return scoreDetailsMapper.findMap(judgeScoreDetails, SqlUtil.formatParametersForAlias(parameters));
    }

    @Override
    public List<ScoreDetails> loadModels() {
        return this.loadModels(null, null, null, null, -1, -1);
    }

    @Override
    public List<ScoreDetails> loadModels(String condition, Object[] values, String order, String sort, int curPage, int limit) {
        return this.loadModels(null, condition, values, order, sort, curPage, limit);
    }

    @Override
    public List<ScoreDetails> loadModels(String[] parameters, String condition, Object[] values, String order, String sort, int curPage, int limit) {
        return scoreDetailsMapper.loadModels(SqlUtil.formatParameters(parameters), SqlUtil.fillCondition(condition, values), order, sort, SqlUtil.getOffset(curPage, limit), limit);
    }

    @Override
    public List<Map<String, Object>> loadMaps() {
        String[][] parameters = {{"judge_score_details", "judgeScoreDetails"}, {"target_id", "targetId"}, {"score", "score"}, {"socre_suggestion", "socreSuggestion"}};
        return this.loadMaps(parameters, null, null, null, null, -1, -1);
    }

    @Override
    public List<Map<String, Object>> loadMaps(String condition, Object[] values, String order, String sort, int curPage, int limit) {
        String[][] parameters = {{"judge_score_details", "judgeScoreDetails"}, {"target_id", "targetId"}, {"score", "score"}, {"socre_suggestion", "socreSuggestion"}};
        return this.loadMaps(parameters, condition, values, order, sort, curPage, limit);
    }

    @Override
    public List<Map<String, Object>> loadMaps(String[][] parameters, String condition, Object[] values, String order, String sort, int curPage, int limit) {
        return scoreDetailsMapper.loadMaps(SqlUtil.formatParametersForAlias(parameters), SqlUtil.fillCondition(condition, values), order, sort, SqlUtil.getOffset(curPage, limit), limit);
    }

    @Override
    public long count() {
        return this.count(null, false);
    }

    @Override
    public long count(String condition, Object[] values) {
        return this.count(null, condition, values, false);
    }

    @Override
    public long count(String[] parameters, boolean isDistinct) {
        return this.count(parameters, null, null, isDistinct);
    }

    @Override
    public long count(String[] parameters, String condition, Object[] values, boolean isDistinct) {
        return scoreDetailsMapper.count(SqlUtil.formatParameters(parameters), SqlUtil.fillCondition(condition, values), isDistinct);
    }

}
